from selenium import webdriver
from selenium.webdriver.support.ui import Select

def initia_driver():
    driver = webdriver.Chrome()
    driver.get('http://cdn1.python3.vip/files/selenium/test2.html')
    return driver

def check_radio(driver):
    radio = driver.find_element_by_css_selector('div#s_radio input[checked="checked"]')
    print(radio.get_attribute('value'))
    driver.find_element_by_css_selector('div#s_radio input[value="小雷老师"]').click()

def check_checkbox(driver):
    allClicked = driver.find_elements_by_css_selector('div#s_checkbox input[checked="checked"]')
    for element in allClicked:
        print(element.get_attribute('value'))
        element.click()
    driver.find_element_by_css_selector('div#s_checkbox input[value="小雷老师"]').click()

def check_select_single(driver):
    # 单选框
    select = Select(driver.find_element_by_css_selector('#ss_single'))
    select.select_by_visible_text("小雷老师")

def check_select_multi(driver):
    # 多选框
    select = Select(driver.find_element_by_css_selector('#ss_multi'))
    # 清除所有选中项
    select.deselect_all()
    select.select_by_visible_text('小江老师')
    select.select_by_visible_text('小雷老师')

driver = initia_driver()
check_radio(driver)
check_checkbox(driver)
check_select_single(driver)
check_select_multi(driver)